package com.yonyou.pmclouds.async.injvm;

import com.yonyou.pmclouds.async.AsyncTaskPusher;
import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableConfigurationProperties(InJvmAsynInvocationConfiguration.InJvmAsyncProperties.class)
public class InJvmAsynInvocationConfiguration {

    @Bean
    public AsyncInvocationQueueExecutor asyncInvocationQueueExecutor() {
        return new AsyncInvocationQueueExecutor();
    }

    @Bean
    public AsyncTaskPusher inJvmAsyncPusher() {
        return new InJvmAsyncTaskPusherImpl();
    }

    @Setter
    @Getter
    @ConfigurationProperties(prefix = "pmcloud.async.in-jvm")
    public static class InJvmAsyncProperties {
        /**
         * 执行器核心线程数
         */
        private int corePoolSize = 50;
        /**
         * 执行器最大线程数
         */
        private int maximumPoolSize = 200;
        /**
         * 线程保留时间
         */
        private int keepAliveTime = 3600;
        /**
         * 待执行队列最大长度
         */
        private int maxWaitInvocation = 2048;
    }
}
